package com.can.service.user.impl;

import com.can.entityDTO.UserDTO;
import com.can.entity.User;
import com.can.mapper.UserMapper;
import com.can.service.user.IUserService;
import com.can.utils.PasswordHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Descripton 用户service层口访问接口实现
 * @Author can
 * @Date 2018/8/28
 * @Version 1.0
 */
@Service(value = "userService")
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insert(UserDTO user) {
        return userMapper.insert(user);
    }

    @Override
    public int register(UserDTO userDTO) {
        userDTO.setSalt(PasswordHelper.generateSalt());
        userDTO.setPassword(PasswordHelper.encryptPassword(userDTO.getPassword(),userDTO.getAccount(),userDTO.getSalt()));
        User user = new User();
        BeanUtils.copyProperties(userDTO,user);
        return userMapper.insert(userDTO);
    }
}
